﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Nirvana
{
    public class WaitLoadSprite : CustomYieldInstruction
    {
        private SpriteCache spritecache;
        public Sprite LoadedObject { get; private set; }
        public string Error { get; private set; }

        public WaitLoadSprite(SpriteCache cache)
        {
            this.spritecache = cache;
        }

        public override bool keepWaiting
        {
            get
            {
                if (!string.IsNullOrEmpty(this.spritecache.Error))
                {
                    this.Error = this.spritecache.Error;
                    return false;
                }

                if (this.spritecache.IsNotNull())
                {
                    this.LoadedObject = this.spritecache.GetObject();
                    return false;
                }
                return true;
            }
        }
    }
}


